<template>
	<view class="message">
		<view class="header">
			<view class="desc">{{sendTime}}</view>
			<view class="opt" @tap="delMessage">删除</view>
		</view>
		<view class="content">{{msg}}</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: null,
				readFlag: null,
				refId: null,
				sendTime: '',
				msg: ''
			}
		},
		// 获取上个页面的url传参
		onLoad: function(options) {
			let that = this
			that.id = options.id
			that.readFlag = options.readFlag == "true" ? true : false
			that.refId = options.refId
			if (!that.readFlag) {
				that.ajax(that.url.updateUnreadMessage, "POST", {
					"id": that.refId
				}, function(resp) {
					console.log("消息更新成已读状态")
				})
			}
		},
		onShow: function() {
			let that = this
			// 动态改变标题栏
			uni.setNavigationBarTitle({
				title: "系统通知"
			})
			that.ajax(that.url.searchMessageById, "POST", {
				"id": that.id
			}, function(resp) {
				let result = resp.data.result
				console.log(result)
				that.sendTime = result.sendTime
				that.msg = result.msg
			})
		},
		methods: {
			deleteMsg() {
				let that = this
				uni.showModal({
					title: "提示信息",
					content: "是否要删除这条消息？",
					success: function(resp) {
						if (resp.confirm) {
							that.ajax(that.url.deleteMessageRefById, "POST", {
								"id": that.refId
							}, function(resp) {
								uni.showToast({
									icon: "success",
									title: "删除成功",
									complete() {
										setTimeout(() => {
											// 返回上一页
											uni.navigateBack({
												delta: 1
											})
										}, 1000)
									}
								})
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="less">
	@import url("message.less");
</style>
